package com.qfedu.sca.config;

import feign.RequestInterceptor;
import feign.RequestTemplate;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;

/**
 * 千锋Java,为你而生！
 *
 * @Author: Feri
 * @Date:2024/11/8 11:11
 * @Modified:
 */
public class FeignRequestInterceptor implements RequestInterceptor {
    @Override
    public void apply(RequestTemplate requestTemplate) {
        //1.获取原来的请求对象
        ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
        HttpServletRequest request=attributes.getRequest();
        //2.获取需要传递的请求消息头的内容
        String token=request.getHeader("scatoken");
        //3.添加到本次请求的消息头中
        requestTemplate.header("scatoken",token);

    }
}